package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "套餐相关接口")
@RequestMapping("/admin/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 功能描述: 添加套餐
     *
     * @return : com.sky.result.Result
     */
    @ApiOperation("添加套餐")
    @PostMapping
    public Result save(@ApiParam("套餐DTO") @RequestBody SetmealDTO setmealDTO) {
        setmealService.save(setmealDTO);
        return Result.success();
    }

    /**
     * 功能描述: 套餐分页
     * @return : com.sky.result.Result<com.sky.result.PageResult>
     */
    @ApiOperation("套餐分页")
    @GetMapping("/page")
    public Result<PageResult> page(@ApiParam("套餐DTO") SetmealPageQueryDTO setmealPageQueryDTO) {
        PageResult result = setmealService.page(setmealPageQueryDTO);
        return Result.success(result);
    }
    /**
     * 功能描述: 套餐停售起售
     * @return : com.sky.result.Result
     */
    @ApiOperation("套餐停售起售")
    @PostMapping("/status/{status}")
    public Result editStatus(@ApiParam("状态") @PathVariable Integer status,Long id){
        setmealService.editStatus(status,id);
        return Result.success();
    }
    /**
     * 功能描述: 批量删除
     * @return : com.sky.result.Result
     */
    @ApiParam("批量删除")
    @DeleteMapping
    public Result delete(@ApiParam("套餐DTO") @RequestParam("ids") List<Long> ids){
        setmealService.delete(ids);
        return Result.success();
    }
    /**
     * 功能描述: 套餐修改
     * @return : com.sky.result.Result
     */
    @ApiOperation("套餐修改")
    @PutMapping
    public Result update(@ApiParam("套餐DTO") @RequestBody SetmealDTO setmealDTO){
        setmealService.update(setmealDTO);
        return Result.success();
    }
    /**
     * 根据id查询套餐，用于修改页面回显数据
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询套餐")
    public Result<SetmealVO> getById(@PathVariable Long id) {
        SetmealVO setmealVO = setmealService.getByIdWithDish(id);
        return Result.success(setmealVO);
    }
}
